package com.sec.android.app.myfiles.module.optimizestorage;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;

/**
 * Created by daesu83.kim on 2016-10-07.
 */

public class OptimizeStorageFileRecord extends FileRecord {

    public static boolean mOverviewWorking = false;
    public static boolean mResultListWorking = false;

    private OptimizeStorageType mOptimizeStorageType;

    public OptimizeStorageFileRecord(int id, String path, String name, long size, long date, int fileType, int isHidden, int itemCount, int itemCountHidden) {
        super(StorageType.OptimizeStorage, id, path, name, size, date, fileType, isHidden, itemCount, itemCountHidden);
    }

    public OptimizeStorageFileRecord(String fullPath) {
        mStorageType = StorageType.OptimizeStorage;
        mPath = "";
        mName = fullPath.substring(fullPath.lastIndexOf('/') + 1, fullPath.length());
        mOptimizeStorageType = getOptimizeStorageType(fullPath);
    }

    @Override
    public String getDisplayName(Context context) {
        return getOptimizeTypeName(context, mOptimizeStorageType);
    }

    @Override
    public boolean isRoot() {
        return true;
    }

    @Override
    public boolean exists(Context context) {
        return true;
    }

    @Override
    protected int _getId() {
        return 0;
    }

    @Override
    protected Uri _getUri(Context context) {
        return null;
    }

    public OptimizeStorageType getOptimizeStorageType() {
        return mOptimizeStorageType;
    }

    public static String getOptimizeStoragePath(OptimizeStorageType type) {
        String ret;
        switch (type) {
            case Overview:
                ret = AppConstants.StoragePath.OPTIMIZE_STORAGE_OVERVIEW;
                break;
            case LargeFiles:
                ret = AppConstants.StoragePath.OPTIMIZE_STORAGE_LARGE_FILES;
                break;
            case UnusedFiles:
                ret = AppConstants.StoragePath.OPTIMIZE_STORAGE_UNUSED_FILES;
                break;
            case DuplicateFiles:
                ret = AppConstants.StoragePath.OPTIMIZE_STORAGE_DUPLICATE_FILES;
                break;
            case UnnecessaryData:
                ret = AppConstants.StoragePath.OPTIMIZE_STORAGE_UNNECESSARY_DATA;
                break;
            default:
                ret = "";
                break;
        }
        return ret;
    }

    public static OptimizeStorageType getOptimizeStorageType(String path) {
        OptimizeStorageType ret = OptimizeStorageType.None;
        if (AppConstants.StoragePath.OPTIMIZE_STORAGE_OVERVIEW.equals(path)) {
            ret = OptimizeStorageType.Overview;
        } else if (AppConstants.StoragePath.OPTIMIZE_STORAGE_LARGE_FILES.equals(path)) {
            ret = OptimizeStorageType.LargeFiles;
        } else if (AppConstants.StoragePath.OPTIMIZE_STORAGE_UNUSED_FILES.equals(path)) {
            ret = OptimizeStorageType.UnusedFiles;
        } else if (AppConstants.StoragePath.OPTIMIZE_STORAGE_DUPLICATE_FILES.equals(path)) {
            ret = OptimizeStorageType.DuplicateFiles;
        } else if (AppConstants.StoragePath.OPTIMIZE_STORAGE_UNNECESSARY_DATA.equals(path)) {
            ret = OptimizeStorageType.UnnecessaryData;
        }
        return ret;
    }

    public static String getOptimizeTypeName(Context context, OptimizeStorageType type) {
        String ret = "";
        Resources res = context.getResources();
        switch (type) {
            case LargeFiles:
                ret = res.getString(R.string.large_files);
                break;

            case UnusedFiles:
                ret = res.getString(R.string.unused_files);
                break;

            case DuplicateFiles:
                ret = res.getString(R.string.duplicate_files);
                break;

            case UnnecessaryData:
                ret = res.getString(R.string.unnecessary_data);
                break;
        }
        return ret;
    }

    public static boolean isWorking() {
        return mOverviewWorking || mResultListWorking;
    }
}
